/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataObject;

import java.io.Serializable;

/**
 *
 * @author Backkom
 */
public class TableObject implements Serializable {

    private static final long serialVersionUID = 1L;
    protected int NUM_ATTRIBUTES = 0;
    protected Object[] parameters;
    protected Class[] dataTypes;

    public Class getDataTypeAt(int index) {
        if (index < NUM_ATTRIBUTES && index >= 0) {
            return dataTypes[index];
        }
        return Object.class;
    }

    public Object getAttributeAt(int index) {
        if (index < NUM_ATTRIBUTES && index >= 0) {
            return parameters[index];
        }
        return null;
    }

    public void setAttributeAt(int index, Object value, Class cls) {
        if (index < parameters.length && index >= 0) {
            parameters[index] = value;
            dataTypes[index] = cls;
        }
    }

    public void setAttributeAt(int index, Object value) {
        if (index < parameters.length && index >= 0) {
            parameters[index] = value;
            dataTypes[index] = value.getClass();
        }
    }

    public boolean setValues(Object[] values, Class[] classes) {
        if (NUM_ATTRIBUTES != values.length || NUM_ATTRIBUTES != classes.length) {
            return false;
        }
        parameters = values;
        dataTypes = classes;
        return true;
    }

    public int getNumAttribute() {
        return NUM_ATTRIBUTES;
    }

    public TableObject(Object[] attributeValues) {
        NUM_ATTRIBUTES = attributeValues.length;
        parameters = attributeValues;
        dataTypes = new Class[NUM_ATTRIBUTES];
        for (int i = 0; i < NUM_ATTRIBUTES; i++) {
            Class cls = attributeValues[i].getClass();
            dataTypes[i] = cls;
        }
    }

    public TableObject(int numAttributes) {
        NUM_ATTRIBUTES = numAttributes;
        parameters = new Object[numAttributes];
        dataTypes = new Class[numAttributes];
        for (int i = 0; i < numAttributes; i++) {
            dataTypes[i] = String.class;
        }
    }

    public boolean hasNull() {
        for (int i = 0; i < NUM_ATTRIBUTES; i++) {
            if (parameters[i] == null && dataTypes[i] != Boolean.class) {
                return true;
            }
        }
        return false;
    }    
}
